<div class="row">
	<div class="col-md-12">
		<form id="addForm" class="form-horizontal" action="${request.contextPath}/cms/tag/add" method="post" onsubmit="return false">
			<div class="box-body" >
				<div class="form-group">
					<label id="tagNameLabel" for="tagName" class="col-sm-2 control-label">名称</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="name" id="tagName" placeholder="输入名称...">
					</div>
				</div>
				
				<div class="form-group">
					<label id="tagWhetherNewLabel" for="tagWhetherNew" class="col-sm-2 control-label">是否最新</label>
					<div class="col-sm-4">
						<select class="form-control" id="tagWhetherNew"  name="whetherNew" style="width: 100%;">
						</select>
					</div>
					<label id="tagWhetherHotLabel" for="tagWhetherHot" class="col-sm-2 control-label">是否最热</label>
					<div class="col-sm-4">
						<select class="form-control" id="tagWhetherHot"  name="whetherHot" style="width: 100%;">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="tagStatusLabel" for="tagStatus" class="col-sm-2  control-label">状态</label>
					<div class="col-sm-2">
						<select class="form-control" id="tagStatus"  name="status" style="width: 100%;">
						</select>
					</div>
				</div>
				<div class="error-message text-center" id="addFormErrorMsgContainer">
					<span class="error-icon"></span>
					<span id="addFormErrorMsg" class="error-msg" ></span>
				</div>
			</div>
			<div class="box-body">
				<div class="pull-right">
					<button type="submit" class="btn btn-primary btn-sm" ><i class="fa fa-save"></i> 保存</button>
					<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 取消</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
function ajaxSubmit(form) {
	
	var $form = $(form);
	
	if ($form.length === 1 && $form.validate()) {
		$.post(form.action, $form.serialize(),
			function(result) {
				if (result.success) {
					$("#lgModal").modal('hide');
		        	alertMsg(result.message,"success");
					dataGridReload();
				} else {
					$form.find(".error-msg").show();
					$form.find(".error-msg").html(result.message);
				}
			}, 'json');
	}
}

$(function() {

    $("#tagStatus").select2({
        data: StatusStore,
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    });
    var $tagWhetherNew = $("#tagWhetherNew");
    $tagWhetherNew.select2({
        data: WhetherStore,
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    });
	var $tagWhetherHot = $("#tagWhetherHot");
	$tagWhetherHot.select2({
		data: WhetherStore,
		theme: "bootstrap",
		minimumResultsForSearch: Infinity
	});

	var $addForm = $("#addForm");
	$addForm.validate({
		rules: {
            name: {
				required: true
			},
            status: {
				required: true
			}
		},
		messages: {
            name:{
				required:"名称不能为空！"
			},
            status:{
				required:"状态不能为空！"
			}
		},
		submitHandler:ajaxSubmit,
		errorLabelContainer:"#addFormErrorMsgContainer",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$addForm.find(".error-msg").html(errorList[0].message);
			}else{
				$addForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>